package com.gxc.service.user.feign;

import com.gxc.service.common.model.ServerResponse;
import com.gxc.service.user.model.dto.GetFeignTestDto;
import com.gxc.service.user.model.dto.ProductDto;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * GoodsFeign Fallback Factory
 *
 * @author GongXincheng
 * @since 2019-11-08 22:07
 */
@Slf4j
@Component
public class GoodsFeignFallbackFactory implements FallbackFactory<GoodsFeign> {
    @Override
    public GoodsFeign create(Throwable throwable) {
        return new GoodsFeign() {
            @Override
            public ServerResponse<List<ProductDto>> add() {
                log.error("GoodsFeign#add() has error：{}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }

            @Override
            public ServerResponse<ProductDto> findById(Long id) {
                log.error("GoodsFeign#findById() has error：{}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }

            @Override
            public ServerResponse<List<ProductDto>> likeSearch(String name) {
                log.error("GoodsFeign#likeSearch() has error：{}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }

            @Override
            public ServerResponse<ProductDto> save(ProductDto entity) {
                log.error("GoodsFeign#save() has error：{}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }

            @Override
            public ServerResponse<GetFeignTestDto> feignGetTest(GetFeignTestDto dto) {
                log.error("GoodsFeign#feignGetTest() has error：{}", throwable.getMessage());
                throw new RuntimeException(throwable);
            }
        };
    }
}
